package com.web_bloks.mvc.client.test;

import com.google.gwt.core.client.GWT;
import com.google.gwt.junit.client.GWTTestCase;
import com.web_bloks.mvc.client.Facade;
import com.web_bloks.mvc.client.IMediator;
import com.web_bloks.mvc.client.INotification;
import com.web_bloks.mvc.client.Mediator;
import com.web_bloks.mvc.client.Notification;
import com.web_bloks.mvc.client.View;

/**
 * 
 * @author Jean-Lou Dupont
 *
 */
public class MVCTestView extends GWTTestCase {

	public String getModuleName() {
		return "com.web_bloks.mvc.MVC";
	}
	
	public MVCTestView() {
		super();

	}
	static Facade facade = null;
	static View    view = null;
	
	public void gwtSetUp() {

		if (null==facade)
			facade = new MVCTestFacade();
		
		if (null==view)
			view = GWT.create( View.class );
	}
	
	public void gwtTearDown() {
		view.clear();
	}
	
	public void testView() {

		assertEquals( view.getClass(), com.web_bloks.mvc.client.View.class );
		assertEquals( facade.getClass(), com.web_bloks.mvc.client.test.MVCTestFacade.class );
	}
	
	
	boolean notifReceived = false;
	
	public void testViewObserver() {
		
		IMediator m2 = new Mediator() {
			
			public String[] listNotificationInterests() {
				return new String[] {
					"testNotif1", "testNotif2"	
				};
			}
			
			public void handleNotification(INotification notification) {
				notifReceived = true;
			}
		};
		
		view.registerMediator( m2 );
		
		view.notifyObservers(new Notification("testNotif1",null,null));
		
		assertTrue( notifReceived );
	}
	
	

}//END